//
//  MainViewController.m
//  Shanghai Cuisine
//
//  Created by iOS Two on 14-9-10.
//  Copyright (c) 2014年 iOS Two. All rights reserved.
//

#import "MainViewController.h"
#import "UIImageView+MJWebCache.h"
#import "DetailViewController.h"
#import "NSTimer+Addition.h"
#import "ListViewController.h"
#import "VideoViewController.h"
#import "VideoListViewController.h"
#import "AlbumListViewController.h"
#import "InfoViewController.h"
#import "SettingViewController.h"

@interface MainViewController ()

@property (assign) NSInteger x;
@end

@implementation MainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)viewWillDisappear:(BOOL)animated {
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    if (version >= 7) {
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"img_nav"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    } else {
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"img_navbackbule4"] forBarMetrics:UIBarMetricsDefault];
    }
    [MobClick endLogPageView:@"MainViewController"];

}
-(void)viewWillAppear:(BOOL)animated {
    if (version >= 7) {
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"img_nav"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    } else {
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"img_navbackpuple4"] forBarMetrics:UIBarMetricsDefault];
    }
    [MobClick beginLogPageView:@"MainViewController"];
//    [_mainScorllView.animationTimer resumeTimer];
}
-(void)viewDidDisappear:(BOOL)animated {
//    [_mainScorllView.animationTimer pauseTimer];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self reactionNetCheck];
    if (version >= 7) { // 判断是否是IOS7
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
    }
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 150, 30)];
    titleLabel.text = @"本帮菜";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:24];
    titleLabel.textColor = [UIColor colorWithRed:0.97 green:0.69 blue:0.17 alpha:1];
    self.navigationItem.title = @"返回";
    self.navigationItem.titleView = titleLabel;
//
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0,0,77,44)];
    [button setBackgroundImage:[UIImage imageNamed:@"wode_03"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(goTo) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *btn = [[UIBarButtonItem alloc]initWithCustomView:button];
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    negativeSpacer.width = -15;
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacer,btn, nil];
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.97 green:0.69 blue:0.17 alpha:1];
    [self creatController];
    [self initGCD];
    // Do any additional setup after loading the view.
}
-(void)initGCD {
    [self showIndeterminateProgress];
    dispatch_queue_t aDQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_group_t group = dispatch_group_create();
    dispatch_group_async(group, aDQueue, ^{
        [self downloadImage:nil];
    });
    dispatch_group_async(group, aDQueue, ^{
        [self getData];
    });
    dispatch_group_async(group, aDQueue, ^{
        [self getASIData];
    });
    dispatch_group_async(group, aDQueue, ^{
        [self getVideo];
    });
    dispatch_group_wait(group, DISPATCH_TIME_FOREVER);//其他同类等待
    [HUD hide:YES];
//    dispatch_release(group);
}
-(void)getVideo {
    _videoLink = [[NSMutableArray alloc]init];
    _videoName = [[NSMutableArray alloc]init];
    _videoCover  = [[NSMutableArray alloc]init];
    AVQuery *query = [[AVQuery alloc]initWithClassName:@"video"];
    query.limit = 5;
    query.cachePolicy = kPFCachePolicyCacheElseNetwork;
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        for (int i = 0; i < objects.count; i++) {
            [_videoName addObject:[[objects objectAtIndex:i] objectForKey:@"name"]];
            [_videoLink addObject:[[objects objectAtIndex:i] objectForKey:@"link"]];
            AVFile *file = [[objects objectAtIndex:i] objectForKey:@"cover"];
            [_videoCover addObject:file.url];
        }
        [_mainTable reloadData];
    }];
}
-(void)getASIData {
    ASIHTTPRequest *request = [[ASIHTTPRequest alloc]initWithURL:[NSURL URLWithString:@"http://api.hoto.cn/index.php?appid=4&appkey=573bbd2fbd1a6bac082ff4727d952ba3&deviceid=0F607264FC6318A92B9E13C65DB7CD3C%7C7DB64D6A-18DB-4843-BAD9-0D906C652209%7CC73A6469-0555-4A64-AC37-3A540302FBD0&format=json&loguid=&method=Search.getAlbumList&sessionid=1418610742&uuid=353ED12DEEE49FC5F5DF6F2CB3EC5665&vc=31&vn=v4.5.0&keyword=%E4%B8%8A%E6%B5%B7%E8%8F%9C"]];
    request.username = @"1";
    request.delegate = self;
    request.cachePolicy = ASIAskServerIfModifiedWhenStaleCachePolicy;
    [request startAsynchronous];
}
-(void)requestFinished:(ASIHTTPRequest *)request {
    _titleName = [[NSMutableArray alloc]init];
    _info = [[NSMutableArray alloc]init];
    _cover = [[NSMutableArray alloc]init];
    _albumId = [[NSMutableArray alloc]init];
    SBJsonParser *jsonP = [[SBJsonParser alloc]init];
    if ([request.username isEqualToString:@"1"]) {
        NSArray *array = [[[jsonP objectWithData:[request responseData]] objectForKey:@"result"] objectForKey:@"list"];
        for (int i = 0; i < array.count; i++) {
            [_cover addObject:[[array objectAtIndex:i] objectForKey:@"Cover"]];
            [_info addObject:[[array objectAtIndex:i] objectForKey:@"Intro"]];
            [_albumId addObject:[[array objectAtIndex:i] objectForKey:@"AlbumId"]];
            [_titleName addObject:[[array objectAtIndex:i] objectForKey:@"Title"]];
        }
        [_mainTable reloadData];
    }
}
-(void)downloadImage:(NSString *)url {
    _hotId = [[NSMutableArray alloc]init];
    _hotImg = [[NSMutableArray alloc]init];
    _hotName = [[NSMutableArray alloc]init];
    _hotTips = [[NSMutableArray alloc]init];
    _hotBigImg = [[NSMutableArray alloc]init];
    _hotMaterialArray = [[NSMutableArray alloc]init];
    _hotMaterialQuantity = [[NSMutableArray alloc]init];
    _hotAuxiliaryMaterial = [[NSMutableArray alloc]init];
    _hotAuxiliaryQuantity = [[NSMutableArray alloc]init];
    _hotIntroductionArray = [[NSMutableArray alloc]init];
    AVQuery *query = [[AVQuery alloc]initWithClassName:@"dishName"];
    [query whereKey:@"isHot" equalTo:[NSNumber numberWithBool:YES]];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        for (int i = 0; i < objects.count; i++) {
            [_hotName addObject:[[objects objectAtIndex:i] objectForKey:@"dishName"]];
            [_hotImg addObject:[[objects objectAtIndex:i] objectForKey:@"bannerImg"]];
            [_hotBigImg addObject:[[objects objectAtIndex:i] objectForKey:@"bigImg"]];
            [_hotMaterialArray addObject:[[objects objectAtIndex:i] objectForKey:@"material"]];
            [_hotMaterialQuantity addObject:[[objects objectAtIndex:i] objectForKey:@"materialQuantity"]];
            [_hotId addObject:[[objects objectAtIndex:i] objectForKey:@"objectId"]];
            [_hotTips addObject:[[objects objectAtIndex:i] objectForKey:@"tips"]];
            [_hotAuxiliaryQuantity addObject:[[objects objectAtIndex:i] objectForKey:@"auxiliaryQuantity"]];
            [_hotAuxiliaryMaterial addObject:[[objects objectAtIndex:i] objectForKey:@"auxiliaryMaterial"]];
            [_hotIntroductionArray addObject:[[objects objectAtIndex:i] objectForKey:@"introduction"]];
        }
        [self performSelectorOnMainThread:@selector(updataUI) withObject:nil waitUntilDone:YES];
    }];
}
-(void)updataUI {
    NSMutableArray *viewsArray = [[NSMutableArray alloc]init];
    for (int i = 0; i < 3; i++) {
        UIView *back = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 171)];
        
        UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 171)];
        if (_hotImg.count != 0) {
            [image setImageURLStr:[_hotImg objectAtIndex:i] placeholder:[UIImage imageNamed:@"img_newdish"]];
        }
        [back addSubview:image];
        
        [viewsArray addObject:back];
    }
    [_mainTable reloadData];
    _mainScorllView = [[CycleScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 171) animationDuration:3];
    _mainScorllView.backgroundColor = [[UIColor purpleColor] colorWithAlphaComponent:0.1];
    _mainScorllView.fetchContentViewAtIndex = ^UIView *(NSInteger pageIndex){
        return viewsArray[pageIndex];
    };
    _mainScorllView.totalPagesCount = ^NSInteger(void){
        return 3;
    };
    _mainScorllView.TapActionBlock = ^(NSInteger pageIndex){
        [MobClick event:@"clickAdvTimes"];
        [self clickAdv:pageIndex];
        NSLog(@"点击了第%d个",pageIndex);
    };
    
//    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//    button.frame = CGRectMake(254, 20, 66, 27);
//    [button addTarget:self action:@selector(goTo) forControlEvents:UIControlEventTouchUpInside];
//    [button setBackgroundImage:[UIImage imageNamed:@"img_favor"] forState:UIControlStateNormal];
//    [_mainScorllView addSubview:button];
    
    _mainTable.tableHeaderView = _mainScorllView;
}
-(void)creatController {
    _mainTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, kHeight - 64) style:UITableViewStylePlain];
    _mainTable.delegate = self;
    _mainTable.dataSource = self;
    _mainTable.backgroundColor = [UIColor colorWithRed:0.93 green:0.93 blue:0.93 alpha:1];
    _mainTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    _mainTable.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_mainTable];
    
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 7)];
    image.backgroundColor = [UIColor colorWithRed:0.93 green:0.93 blue:0.93 alpha:1];
    _mainTable.tableFooterView = image;
}
-(void)getData {
    _nameArray = [[NSMutableArray alloc]init];
    _imgArray = [[NSMutableArray alloc]init];
    _bigImg = [[NSMutableArray alloc]init];
    _materialArray = [[NSMutableArray alloc]init];
    _materialQuantity = [[NSMutableArray alloc]init];
    _dishId = [[NSMutableArray alloc]init];
    _tips = [[NSMutableArray alloc]init];
    _auxiliaryMaterial = [[NSMutableArray alloc]init];
    _auxiliaryQuantity = [[NSMutableArray alloc]init];
    _introductionArray = [[NSMutableArray alloc]init];
    AVQuery *query = [[AVQuery alloc]initWithClassName:@"dishName"];
    [query whereKey:@"isHot" notEqualTo:[NSNumber numberWithBool:NO]];
    query.limit = 5;
    query.cachePolicy = kPFCachePolicyCacheElseNetwork;
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        for (int i = 0; i < objects.count; i++) {
            [_nameArray addObject:[[objects objectAtIndex:i] objectForKey:@"dishName"]];
            [_imgArray addObject:[[objects objectAtIndex:i] objectForKey:@"imgUrl"]];
            [_bigImg addObject:[[objects objectAtIndex:i] objectForKey:@"bigImg"]];
            [_materialArray addObject:[[objects objectAtIndex:i] objectForKey:@"material"]];
            [_materialQuantity addObject:[[objects objectAtIndex:i] objectForKey:@"materialQuantity"]];
            [_dishId addObject:[[objects objectAtIndex:i] objectForKey:@"objectId"]];
            [_tips addObject:[[objects objectAtIndex:i] objectForKey:@"tips"]];
            [_auxiliaryQuantity addObject:[[objects objectAtIndex:i] objectForKey:@"auxiliaryQuantity"]];
            [_auxiliaryMaterial addObject:[[objects objectAtIndex:i] objectForKey:@"auxiliaryMaterial"]];
            [_introductionArray addObject:[[objects objectAtIndex:i] objectForKey:@"introduction"]];
        }
        [_mainTable reloadData];
    }];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
    return 134;
    } else if (indexPath.row == 1) {
        return 204;
    } else if (indexPath.row == 2) {
        return 134;
    }
    return 0;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *string;
    if (indexPath.row == 0) {
        string = @"0";
    } else if (indexPath.row) {
        string = @"1";
    } else if (indexPath.row) {
        string = @"2";
    }
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:string];
    if(cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:string];
    } else {
        for (UIView *view in [cell.contentView subviews]) {
            [view removeFromSuperview];
        }
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor colorWithRed:0.93 green:0.93 blue:0.93 alpha:1];
    
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 7, kwidth, 22.5)];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(272, 7, 47, 22.5);
    button.tag = indexPath.row;
    [button addTarget:self action:@selector(more:) forControlEvents:UIControlEventTouchUpInside];
    if (indexPath.row == 0) {
        UIScrollView *scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 30, kwidth, 112)];
        scroll.contentSize = CGSizeMake(135 * 5 + 8, 112);
        scroll.showsHorizontalScrollIndicator = NO;
        [cell.contentView addSubview:scroll];
        for (int i = 0; i < _imgArray.count; i++) {
            UIImageView *dish = [[UIImageView alloc]initWithFrame:CGRectMake(8 + i * 135, 7, 125.5, 95.5)];
            [dish setImageURLStr:[_imgArray objectAtIndex:i] placeholder:[UIImage imageNamed:@"11_08"]];
            dish.layer.borderWidth = 1;
            dish.layer.borderColor = [[UIColor whiteColor] CGColor];
            dish.userInteractionEnabled = YES;
            dish.tag = i;
            [dish addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buttonClick:)]];
            [scroll addSubview:dish];
            
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(9 + i * 135, 78, 123.5, 23.5)];
            label.text = [_nameArray objectAtIndex:i];
            label.textColor = [UIColor colorWithRed:0.99 green:0.7 blue:0.18 alpha:1];
            label.font = [UIFont systemFontOfSize:14];
            label.textAlignment = NSTextAlignmentCenter;
            label.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
            [scroll addSubview:label];
        }
        image.image = [UIImage imageNamed:@"11_05"];
        
    } else if (indexPath.row == 1) {
        image.image = [UIImage imageNamed:@"11_11"];
        
        UIView *back = [[UIView alloc]initWithFrame:CGRectMake(5, 40, 311, 91)];
        back.backgroundColor = [UIColor whiteColor];
        back.layer.shadowColor = [UIColor grayColor].CGColor;
        back.layer.shadowOffset = CGSizeMake(2, 2);
        back.layer.shadowOpacity = 0.5;
        back.layer.shadowRadius = 1.0;
        back.layer.borderWidth = 1.0;
        back.layer.borderColor = [[UIColor colorWithRed:0.75 green:0.71 blue:0.7 alpha:1] CGColor];
        back.tag = 0;
        [back addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAnthor:)]];
        [cell.contentView addSubview:back];
        
        UIImageView *dish = [[UIImageView alloc]initWithFrame:CGRectMake(20, 34, 49, 49)];
        [dish setImageURLStr:[_cover objectAtIndex:0] placeholder:[UIImage imageNamed:@"11_14"]];
        [back addSubview:dish];
        
        CGSize sizeName = [[_titleName objectAtIndex:0] sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(220, 0.0) lineBreakMode:NSLineBreakByWordWrapping];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 4, 311, 20)];
        label.text = [_titleName objectAtIndex:0];
        label.font = [UIFont systemFontOfSize:15];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor colorWithRed:0.25 green:0.07 blue:0 alpha:1];
        [back addSubview:label];
        
        UIImageView *line = [[UIImageView alloc]initWithFrame:CGRectMake(0, 24, sizeName.width + 30, 1)];
        line.backgroundColor = [UIColor colorWithRed:0.72 green:0.68 blue:0.66 alpha:1];
        line.center = CGPointMake(label.center.x, 24);
        [back addSubview:line];
        
        UILabel *info = [[UILabel alloc]initWithFrame:CGRectMake(80, 33, 230, 100)];
        info.text = [_info objectAtIndex:0];
        info.numberOfLines = 3;
        info.textColor = [UIColor colorWithRed:0.27 green:0.27 blue:0.27 alpha:1];
        info.font = [UIFont systemFontOfSize:13];
        [info sizeToFit];
        [back addSubview:info];
        
        for (int i = 1; i < 5; i++) {
            UIImageView *another = [[UIImageView alloc]initWithFrame:CGRectMake((i - 1) * 78 + 5, 96.5 + 26 + 10, 77, 66)];
            [another setImageURLStr:[_cover objectAtIndex:i] placeholder:[UIImage imageNamed:@"11_17"]];
            another.tag = i;
            another.userInteractionEnabled = YES;
            another.layer.shadowColor = [UIColor grayColor].CGColor;
            another.layer.shadowOffset = CGSizeMake(2, 2);
            another.layer.shadowOpacity = 0.5;
            another.layer.shadowRadius = 1.0;
            [another addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAnthor:)]];
            [cell.contentView addSubview:another];
        }
    } else if (indexPath.row == 2) {
        UIScrollView *scroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 30, kwidth, 112)];
        scroll.contentSize = CGSizeMake(131.5 * 5 + 10, 112);
        scroll.showsHorizontalScrollIndicator = NO;
        [cell.contentView addSubview:scroll];
        for (int i = 0; i < _videoName.count; i++) {
            UIImageView *dish = [[UIImageView alloc]initWithFrame:CGRectMake(10 + i * 131.5, 7, 120, 70)];
            [dish setImageURLStr:[_videoCover objectAtIndex:i] placeholder:[UIImage imageNamed:@"11_08"]];
//            dish.layer.borderWidth = 1;
//            dish.layer.borderColor = [[UIColor whiteColor] CGColor];
            dish.userInteractionEnabled = YES;
            dish.tag = i;
            [dish addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(videoClick:)]];
            [scroll addSubview:dish];
            
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(9 + i * 131.5, 78, 123.5, 23.5)];
            label.text = [_videoName objectAtIndex:i];
            label.textColor = [UIColor colorWithRed:0.38 green:0.33 blue:0.3 alpha:1];
            label.font = [UIFont systemFontOfSize:14];
            label.textAlignment = NSTextAlignmentCenter;
//            label.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
            [scroll addSubview:label];
        }
        
        image.image = [UIImage imageNamed:@"label_06"];
    }
    [cell.contentView addSubview:image];
    [cell.contentView addSubview:button];

    return cell;
}
-(void)more:(UIButton *)sender {
    if (sender.tag == 0) {
        ListViewController *list = [[ListViewController alloc]init];
        [self.navigationController pushViewController:list animated:YES];
    } else if (sender.tag == 1) {
        AlbumListViewController *album = [[AlbumListViewController alloc]init];
        [self.navigationController pushViewController:album animated:YES];
    } else if (sender.tag == 2) {
        VideoListViewController *video = [[VideoListViewController alloc]init];
        [self.navigationController pushViewController:video animated:YES];
    }
}
-(void)videoClick:(UITapGestureRecognizer *)tap {
    _x = tap.view.tag;
    if ([[self netWorkType] isEqualToString:@"wifi"]) {
        VideoViewController *video = [[VideoViewController alloc]init];
        video.videoLink = [_videoLink objectAtIndex:tap.view.tag];
        video.videoName = [_videoName objectAtIndex:tap.view.tag];
        self.navigationItem.title = @"返回";
        [self.navigationController pushViewController:video animated:YES];
    } else if ([[self netWorkType] isEqualToString:@"gprs"]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"当前网络不适合观看视频,是否继续?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alert show];
    } else if ([[self netWorkType] isEqualToString:@"nil"]) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"当前网络不给力,请稍后再试试" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
    }
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 1) {
        VideoViewController *video = [[VideoViewController alloc]init];
        video.videoLink = [_videoLink objectAtIndex:_x];
        video.videoName = [_videoName objectAtIndex:_x];
        self.navigationItem.title = @"返回";
        [self.navigationController pushViewController:video animated:YES];
    }
}
-(void)clickAnthor:(UITapGestureRecognizer *)sender {
    InfoViewController *info = [[InfoViewController alloc]init];
    info.albumId = [_albumId objectAtIndex:sender.view.tag];
    [self.navigationController pushViewController:info animated:YES];
}
-(void)buttonClick:(UITapGestureRecognizer *)sender {
    [MobClick event:@"clickImage"];
    DetailViewController *detail = [[DetailViewController alloc]init];
    detail.name = [_nameArray objectAtIndex:sender.view.tag];
    detail.bigImg = [_bigImg objectAtIndex:sender.view.tag];
    detail.dishId = [_dishId objectAtIndex:sender.view.tag];
    detail.materialArray = [_materialArray objectAtIndex:sender.view.tag];
    detail.materialQuantity = [_materialQuantity objectAtIndex:sender.view.tag];
    detail.tips = [_tips objectAtIndex:sender.view.tag];
    detail.auxiliaryMaterial = [_auxiliaryMaterial objectAtIndex:sender.view.tag];
    detail.auxiliaryQuantity = [_auxiliaryQuantity objectAtIndex:sender.view.tag];
    detail.introduction = [_introductionArray objectAtIndex:sender.view.tag];
    detail.smallImg = [_imgArray objectAtIndex:sender.view.tag];
    [self.navigationController pushViewController:detail animated:YES];
}
-(void)goTo {
    SettingViewController *setting = [[SettingViewController alloc]init];
    [self.navigationController pushViewController:setting animated:YES];
}

-(void)clickAdv :(NSInteger)index {
    if (_hotImg.count != 0) {
        DetailViewController *detail = [[DetailViewController alloc]init];
        detail.name = [_hotName objectAtIndex:index];
        detail.bigImg = [_hotBigImg objectAtIndex:index];
        detail.dishId = [_hotId objectAtIndex:index];
        detail.materialArray = [_hotMaterialArray objectAtIndex:index];
        detail.materialQuantity = [_hotMaterialQuantity objectAtIndex:index];
        detail.tips = [_hotTips objectAtIndex:index];
        detail.auxiliaryMaterial = [_hotAuxiliaryMaterial objectAtIndex:index];
        detail.auxiliaryQuantity = [_hotAuxiliaryQuantity objectAtIndex:index];
        detail.introduction = [_hotIntroductionArray objectAtIndex:index];
        detail.smallImg = [_hotImg objectAtIndex:index];
        [self.navigationController pushViewController:detail animated:YES];
    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
